package com.code.zjm;

import android.content.Context;
import android.hardware.Sensor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

/**
 * Created by ZJM on 2017/6/30.
 */

public class SensorAdapter extends BaseAdapter {

    private Context context;
    private List<Sensor> sensors;

    public SensorAdapter(Context context, List<Sensor> sensors) {
        this.context = context;
        this.sensors = sensors;
    }

    @Override
    public int getCount() {
        return sensors.size();
    }

    @Override
    public Object getItem(int position) {
        return sensors.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (sensors == null) {
            throw new IllegalArgumentException("sensor list is null!");
        }
        Sensor sensor = sensors.get(position);
//        RelativeLayout sensorsLayout;
        TextView textView;
        if (convertView != null) {  //获取系统回收的对象
            textView = (TextView) convertView;
        } else {
            textView = (TextView) LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, null);
        }

        textView.setText(sensor.getName());

//        TextView sensorName = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_name);
//        TextView sensorType = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_type);
//        TextView sensorMaxRange = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_max_range);
//        TextView sensorMinDelay = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_min_delay);
//        TextView sensorPower = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_power);
//        TextView sensorResolution = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_resolution);
//        TextView sensorVendor = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_vendor);
//        TextView sensorVersion = (TextView) sensorsLayout.findViewById(R.id.tv_sensor_version);
//
//        sensorName.setText(sensor.getName());
//        sensorType.setText(sensor.getType());
//        sensorMaxRange.setText(sensor.getMaximumRange()+"");
//        sensorMinDelay.setText(sensor.getMinDelay());
//        sensorPower.setText(sensor.getPower()+"");
//        sensorResolution.setText(sensor.getResolution()+"");
//        sensorVendor.setText(sensor.getVendor());
//        sensorVersion.setText(sensor.getVersion());

        return textView;
    }
}
